package com.tshopping.dao;

import com.tshopping.bean.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

@Repository
public interface UserDao {

    @Select("select * from user where email = #{email} and password = #{password}")
    User findUserByEmailAndPassword(@Param("email") String email, @Param("password") String password);

    @Insert("insert into user (email,password) values (#{email},#{password})")
    boolean insertUser(@Param("email") String email,@Param("password") String password);

    @Update("update user set password = #{password} where email = #{email}")
    boolean updateUserPasswordByEmail(@Param("email") String email, @Param("password") String password);

    @Select("select count(*) from user where email = #{email}")
    int findUserCountByEmail(@Param("email") String email);

    @Update("update user set password = #{newPassword} where password = #{oldPassword} and email = #{email}")
    boolean updateUserPasswordByOldPassword(@Param("newPassword") String newPassword,@Param("oldPassword") String oldPassword,@Param("email") String email);

    @Update("update user set screenName = #{screenName},name = #{name},sex = #{sex},phone = #{phone},headPortrait=#{headPortrait} where email = #{email}")
    boolean updateUserByEmail(@Param("screenName") String screenName, @Param("name") String name, @Param("sex") String sex, @Param("phone") String phone, @Param("email") String email, @Param("headPortrait") String head);

    @Update("update user set account=account+#{account} where id=#{id}")
    boolean addAccountById(@Param("account")double account,@Param("id")int id);

    @Update("update user set account=account-#{account} where id=#{id}")
    boolean payAccountById(@Param("account")double account,@Param("id")int id);

    @Select("select count(*) from user")
    int selectUserCount();

    @Select("select * from user limit #{start},#{size}")
    ArrayList<User> selectAllUser(@Param("start")int start,@Param("size")int size);

    @Update("update user set isValid=#{isValid} where id=#{id}")
    boolean updateUserIsValid(@Param("isValid")int isValid,@Param("id")int id);

    @Delete("delete from user where id=#{id}")
    boolean deleteUserById(@Param("id")int id);

    @Update("update user set role=#{role} where id=#{id}")
    boolean updateUserRole(@Param("role")int role,@Param("id")int id);
}
